package android.zhcs.myapplication;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.zhcs.myapplication.databinding.ActivityMainActivity2zfcgBinding;
import android.zhcs.myapplication.databinding.Item2Binding;

import androidx.appcompat.app.AppCompatActivity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;

public class MainActivity2zfcg extends AppCompatActivity {


    public static void start(Context c) {
        Intent intent = new Intent(c, MainActivity2zfcg.class);
        c.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainActivity2zfcgBinding binding = ActivityMainActivity2zfcgBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getSupportActionBar().hide();
        String rq = PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).getString("rq", "");
        String sj = PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).getString("sj", "");
        String lx = PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).getString("lx", "");
        binding.lx.setText(lx);
        binding.rq.setText(rq);
        binding.sj.setText(sj);
        binding.zjg.setText("￥" + PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).getString("zjg",""));
        String data = PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).getString("data", "");
        Type type = new TypeToken<ArrayList<bean1>>() {
        }.getType();
        ArrayList<bean1> lsit = new Gson().fromJson(data, type);
        binding.qx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                PreferenceManager.getDefaultSharedPreferences(MainActivity2zfcg.this).edit().clear().apply();
                dlMainActivity2.start(MainActivity2zfcg.this);
            }
        });
        binding.myrec.seta(1, lsit.size(), R.layout.item2, new Cal() {
            @Override
            public void bix(View itemView, int position) {
                Item2Binding inflate = Item2Binding.bind(itemView);
                bean1 b = lsit.get(position);
                inflate.num.setText(b.num + "份");
                inflate.img.setImageResource(R.mipmap.dbz);
                inflate.jg.setText("￥" + b.jg);
                inflate.name.setText(b.name);
            }
        });
    }
}